Fix installing git repos with lockfiles
authorAlex Crichton <alex@alexcrichton.com>
Fri, 11 Mar 2016 20:18:17 +0000 (12:18 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 11 Mar 2016 20:18:41 +0000 (12:18 -0800)
Just an erroneous assertion that needs to be ignored.

Closes #2466

src/cargo/core/resolver/encode.rs
tests/test_cargo_install.rs

index 93d359655c8131b15dbcc9901ba471d3cdde6db7..c2d187c3f09d1744f94adf3ec6ce43cad5a00008 100644 (file)
@@ -95,7 +95,13 @@ fn build_path_deps(root: &Package,
                    map: &mut HashMap<String, SourceId>,
                    config: &Config)
                    -> CargoResult<()> {
-    assert!(root.package_id().source_id().is_path());
+    // If the root crate is *not* a path source, then we're probably in a
+    // situation such as `cargo install` with a lock file from a remote
+    // dependency. In that case we don't need to fixup any path dependencies (as
+    // they're not actually path dependencies any more), so we ignore them.
+    if !root.package_id().source_id().is_path() {
+        return Ok(())
+    }
 
     let deps = root.dependencies()
                    .iter()
index f385086ca113b48fce33796e14c645d8f147ee3e..f4a322f4cd1f4e2985519aaa353abb9740557f83 100644 (file)
@@ -596,3 +596,38 @@ third party subcommand `cargo-fail[..]` exited unsuccessfully
 To learn more, run the command again with --verbose.
 "));
 });
+
+test!(git_with_lockfile {
+    let p = git::repo(&paths::root().join("foo"))
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+
+            [dependencies]
+            bar = { path = "bar" }
+        "#)
+        .file("src/main.rs", "fn main() {}")
+        .file("bar/Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.1.0"
+            authors = []
+        "#)
+        .file("bar/src/lib.rs", "fn main() {}")
+        .file("Cargo.lock", r#"
+            [root]
+            name = "foo"
+            version = "0.1.0"
+            dependencies = [ "b 0.1.0" ]
+
+            [[package]]
+            name = "bar"
+            version = "0.1.0"
+        "#);
+    p.build();
+
+    assert_that(cargo_process("install").arg("--git").arg(p.url().to_string()),
+                execs().with_status(0));
+});